package sunlight.util;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;

public class SystemClipboard implements ClipboardOwner {

	private boolean 	isOwner;
	private Clipboard	Clipboard;
	
	public SystemClipboard(){
		this.Clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		this.isOwner = true;
	}
	
	@Override
	public void lostOwnership(Clipboard clipboard, Transferable contents) {
		this.isOwner = false;
	}
	
	public boolean own(){
		return this.isOwner;
	}
	
	public void setContents(String text){
	    StringSelection stringSelection = new StringSelection(text);
	    this.Clipboard.setContents(stringSelection, this);
	}
}
